package com.example.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Hotel;
import com.example.entity.hotelGroup;
import com.example.mapper.HotelMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import static java.lang.Long.*;


@Service
public class HotelService extends ServiceImpl<HotelMapper, Hotel> {

    @Resource
    private HotelMapper hotelMapper;

    @Resource
    private com.example.mapper.hotelGroupMapper hotelGroupMapper;

    @Transactional
    public void addSetmealSave(String itemGroupids, Hotel hotel) {
        hotelMapper.insert(hotel);
        String [] split = itemGroupids.split(",");
        for (String id : split) {
            hotelGroup hotelGroup = new hotelGroup();
            hotelGroup.setGroupId(valueOf(id));
            hotelGroup.setHotelId(valueOf(Integer.valueOf(hotel.getId().toString())));
            hotelGroupMapper.insert(hotelGroup);//中间表的循环增加
        }
    }
}